<template>
  <div class="container">
    <img :src="img_url+'/mp_3.0/loading.gif'"
         v-if="img_url"
         mode="widthFix"
         alt=""
         class="loading">
  </div>
</template>

<script>
import common from "@/assets/js/mmk_common.js";
export default {
  data () {
    return {
      entry_img_url: "",
      img_base: common.image_response,
      img_url: common.image_resource,
      btn_type: "getUserInfo",
      jump_url: "",
      title: "",
      s_data: {},
      is_show: true,
      isReject: false,
      code: "",
      u_id: "",
      login_data: {},
    };
  },
  onLoad (options) {
    Object.assign(this.$data, this.$options.data());
    console.log(options);
    if (options.scene) {
      let url_data = decodeURIComponent(options.scene),
        obj = {};
      url_data.split("&").forEach(item => {
        obj[item.split("=")[0]] = item.split("=")[1];
      });
      if (obj.sid && obj.t && obj.tg) {
        this.s_data = obj;
        wx.setStorageSync('s_data', this.s_data)
      } else {
        wx.showToast({
          title: "参数不完整", //提示的内容,
          icon: "none", //图标,
          duration: 1500, //延迟时间,
          mask: true, //显示透明蒙层，防止触摸穿透,
          success: res => {
            setTimeout(() => {
              wx.reLaunch({ url: '/pages/index/main' });
            }, 1500);
          }
        });
      }
    } else if (options.t) {
      if (!options.tg) {
        options.tg = 0
      }
      this.s_data = options;
      wx.setStorageSync('s_data', this.s_data)
    } else {
      wx.showToast({
        title: "参数不完整", //提示的内容,
        icon: "none", //图标,
        duration: 1500, //延迟时间,
        mask: true, //显示透明蒙层，防止触摸穿透,
        success: res => {
          setTimeout(() => {
            wx.reLaunch({ url: '/pages/index/main' });
          }, 1500);
        }
      });
    }
    if (this.title != "") {
      wx.setNavigationBarTitle({
        title: this.title
      });
    }
  },
  onReady () {
    this.get_entryData();
  },
  onShow () {
    wx.removeStorage({
      key: 'user_token',
      success: res => { }
    });
    this.get_entryData();
  },
  methods: {
    get_entryData () {
      wx.showLoading({
        title: "加载中", //提示的内容,
        mask: false //显示透明蒙层，防止触摸穿透,
      });
      common.fly_post("api/v4_2/user_jump/url", this.s_data, response => {
        let res = response.data;
        if (res.status_code == 0) {
          wx.hideLoading();
          wx.getStorage({
            key: 'user_token',
            success: (response) => {
              console.log(response.data)
              //   已登录 
              wx.setStorage({
                key: 's_data',
                data: this.s_data
              });
              wx.redirectTo({ url: res.data.jump_url });
            },
            fail: () => {
              //   未登录
              //   已登录 
              wx.setStorage({
                key: 's_data',
                data: this.s_data
              });
              wx.setStorageSync('jump_url', res.data.jump_url)
              wx.redirectTo({
                url: '/pages/package_main/login/main'
              })
            },
            complete: () => { }
          })

        } else {
          wx.showToast({
            title: res.message, //提示的内容,
            icon: "none", //图标,
            duration: 1500, //延迟时间,
            mask: false //显示透明蒙层，防止触摸穿透,
          });
          setTimeout(() => {
            wx.switchTab({ url: '/pages/index/main' });
          }, 1500);
        }
      });
    },
    band_user () {
      let that = this
      common.fly_post(
        "api/v4_2/user/share",
        {
          type: that.s_data.t,
          sid: that.s_data.sid,
          d: that.s_data.d
        },
        response => {
          if (that.s_data.t == 13) {
            wx.reLaunch({ url: (that.jump_url + '&share_id=' + that.s_data.sid) });
            console.log(that.jump_url + '&share_id=' + that.s_data.sid);

          } else {
            wx.reLaunch({ url: that.jump_url });
          }

        }
      );
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  .loading {
    width: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}
</style>


